var _____WB$wombat$assign$function_____=function(name){return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name))||self[name];};if(!self.__WB_pmw){self.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}{ let window = _____WB$wombat$assign$function_____("window"); let self = _____WB$wombat$assign$function_____("self"); let document = _____WB$wombat$assign$function_____("document"); let location = _____WB$wombat$assign$function_____("location"); let top = _____WB$wombat$assign$function_____("top"); let parent = _____WB$wombat$assign$function_____("parent"); let frames = _____WB$wombat$assign$function_____("frames"); let opens = _____WB$wombat$assign$function_____("opens"); jQuery(document).ready(function ($) { // DIAG - Diagnostics = Ver 1.4.2 // if (chatbotSettings.chatbot_chatgpt_diagnostics === 'On') { // console.log('Chatbot: NOTICE: Entering chatbot-chatgpt.js'); // } let chatGptChatBot = $('#chatbot-chatgpt').hide(); messageInput = $('#chatbot-chatgpt-message'); let conversation = $('#chatbot-chatgpt-conversation'); submitButton = $('#chatbot-chatgpt-submit'); uploadfileButton = $('#chatbot-chatgpt-upload-file'); chatGptOpenButton = $('#chatgpt-open-btn'); chatbotChatgptBotName = localStorage.getItem('chatbot_chatgpt_bot_name') || 'Kognetiks Chatbot'; chatbotChatgptBotPrompt = localStorage.getItem('chatbot_chatgpt_bot_prompt') || 'Enter your question ...'; // Determine the shortcode styling where default is 'floating' or 'embedded' - Ver 1.7.1 chatbot_chatgpt_display_style = localStorage.getItem('chatbot_chatgpt_display_style') || 'floating'; chatbot_chatgpt_assistant_alias = localStorage.getItem('chatbot_chatgpt_assistant_alias') || 'original'; initialGreeting = localStorage.getItem('chatbot_chatgpt_initial_greeting') || 'Hello! How can I help you today?'; subsequentGreeting = localStorage.getItem('chatbot_chatgpt_subsequent_greeting') || 'Hello again! How can I help you?'; chatbotChatgptDisplaySytle = localStorage.getItem('chatbot_chatgpt_display_style') || 'floating'; chatbotChatgptAssistantAlias = localStorage.getItem('chatbot_chatgpt_assistant_alias') || 'original'; chatbot_chatgpt_start_status = localStorage.getItem('chatbot_chatgpt_start_status') || 'closed'; chatbot_chatgpt_start_status_new_visitor = localStorage.getItem('chatbot_chatgpt_start_status_new_visitor') || 'closed'; chatbot_chatgpt_disclaimer_setting = localStorage.getItem('chatbot_chatgpt_disclaimer_setting') || 'Yes'; chatbot_chatgpt_width_setting = localStorage.getItem('chatbot_chatgpt_width_setting') || 'Narrow'; // Add variables for the timeout setting - Ver 1.8.8 timeout_setting = localStorage.getItem('chatbot_chatgpt_timeout_setting') || 240; // console.log('Chatbot: NOTICE: timeout_setting: ' + timeout_setting); // Convert the timeout setting to a number timeout_setting = parseInt(timeout_setting); // Convert the timeout setting to milliseconds timeout_setting = timeout_setting * 1000; plugins_url = plugin_vars.plugins_url; // Get an open icon for the chatbot - Ver 1.8.6 chatbotopenicon = plugins_url + '/assets/icons/' + 'chat_FILL0_wght400_GRAD0_opsz24.png'; chatbotopenicon = $('') .attr('id', 'chatbot-open-icon') .attr('class', 'chatbot-open-icon') .attr('src', chatbotopenicon); // Get a collapse icon for the chatbot - Ver 1.8.6 chatbotcollapseicon = plugins_url + '/assets/icons/' + 'close_FILL0_wght400_GRAD0_opsz24.png'; chatbotcollapseicon = $('') .attr('id', 'chatbot-collapse-icon') .attr('class', 'chatbot-collapse-icon') .attr('src', chatbotcollapseicon); // Get am erase icon for the chatbot - Ver 1.8.6 chatboteraseicon = plugins_url + '/assets/icons/' + 'delete_FILL0_wght400_GRAD0_opsz24.png'; chatboteraseicon = $('') .attr('id', 'chatbot-erase-icon') .attr('class', 'chatbot-erase-icon') .attr('src', chatboteraseicon); // console.log('Chatbot: NOTICE: chatbot_chatgpt_start_status: ' + chatbot_chatgpt_start_status); // console.log('Chatbot: NOTICE: chatbot_chatgpt_start_status_new_visitor: ' + chatbot_chatgpt_start_status_new_visitor); // console.log('Chatbot: NOTICE: chatbot_chatgpt_display_style: ' + chatbot_chatgpt_display_style); // console.log('Chatbot: NOTICE: chatbot_chatgpt_width_setting: ' + chatbot_chatgpt_width_setting); // Determine the shortcode styling where default is 'floating' or 'embedded' - Ver 1.7.1 // var site-header = document.querySelector("#site-header"); // var site-footer = document.querySelector("#site-footer"); // if(header && footer) { // var headerBottom = site-header.getBoundingClientRect().bottom; // var footerTop = site-footer.getBoundingClientRect().top; // var visible-distance = footerTop - headerBottom; // console.log('Chatbot: NOTICE: Distance: + distance + 'px'); // } if (chatbot_chatgpt_display_style === 'embedded') { // Apply configurations for embedded style $('#chatbot-chatgpt').addClass('embedded-style').removeClass('floating-style'); // Other configurations specific to embedded style chatbot_chatgpt_start_status = 'open'; // Force the chatbot to open if embedded chatbot_chatgpt_start_status_new_visitor = 'open'; // Force the chatbot to open if embedded localStorage.setItem('chatbot_chatgpt_start_status', chatbot_chatgpt_start_status); localStorage.setItem('chatbot_chatgpt_start_status_new_visitor', chatbot_chatgpt_start_status_new_visitor); chatGptChatBot.addClass('embedded-style').removeClass('floating-style'); } else { // Apply configurations for floating style $('#chatbot-chatgpt').addClass('floating-style').removeClass('embedded-style'); // Other configurations specific to floating style if (chatbot_chatgpt_width_setting === 'Wide') { chatGptChatBot.addClass('wide'); } else { // chatGptChatBot.removeClass('wide').css('display', 'none'); chatGptChatBot.removeClass('wide'); } } // Overrides for mobile devices - Ver 1.8.1 if (isMobile()) { // console.log('Chatbot: NOTICE: chatbot_chatgpt_start_status: ' + chatbot_chatgpt_start_status); // console.log('Chatbot: NOTICE: chatbot_chatgpt_start_status_new_visitor: ' + chatbot_chatgpt_start_status_new_visitor); // console.log('Chatbot: NOTICE: chatbot_chatgpt_display_style: ' + chatbot_chatgpt_display_style); // console.log('Chatbot: NOTICE: chatbot_chatgpt_width_setting: ' + chatbot_chatgpt_width_setting); if ( chatbot_chatgpt_display_style === 'embedded') { // Apply configurations for embedded style chatbot_chatgpt_start_status = 'open'; // Force the chatbot to open if embedded chatbot_chatgpt_start_status_new_visitor = 'open'; // Force the chatbot to open if embedded } // chatbot_chatgpt_start_status = 'closed'; // chatbot_chatgpt_start_status_new_visitor = 'closed'; localStorage.setItem('chatbot_chatgpt_start_status', chatbot_chatgpt_start_status); localStorage.setItem('chatbot_chatgpt_start_status_new_visitor', chatbot_chatgpt_start_status_new_visitor); // Determine the viewport width and height let viewportWidth = window.innerWidth; let viewportHeight = window.innerHeight; // console.log('Viewport Width:', viewportWidth, 'Viewport Height:', viewportHeight); // Determine the orientation const orientation = screen.orientation || screen.mozOrientation || screen.msOrientation; if (orientation.type === 'landscape-primary') { // console.log('Orientation: Landscape'); } else if (orientation.type === 'portrait-primary') { // console.log('Orientation: Portrait'); } else { // console.log('Orientation:', orientation.type); } updateChatbotStyles(); // Listen for orientation changes window.addEventListener('orientationchange', updateChatbotStyles); // Listen for resize events window.addEventListener('resize', updateChatbotStyles); // TODO - IF MOBILE REMOVE ICON AND SHOW DASHICON AND DETERMINE WIDTH AND ORIENTATION (PORTRAIT OR LANDSCAPE) } // console.log('Chatbot: NOTICE: chatbot_chatgpt_start_status: ' + chatbot_chatgpt_start_status); // console.log('Chatbot: NOTICE: chatbot_chatgpt_start_status_new_visitor: ' + chatbot_chatgpt_start_status_new_visitor); // console.log('Chatbot: NOTICE: chatbot_chatgpt_display_style: ' + chatbot_chatgpt_display_style); // console.log('Chatbot: NOTICE: chatbot_chatgpt_width_setting: ' + chatbot_chatgpt_width_setting); if ( chatbot_chatgpt_display_style === 'embedded') { // Apply configurations for embedded style chatbot_chatgpt_start_status = 'open'; // Force the chatbot to open if embedded chatbot_chatgpt_start_status_new_visitor = 'open'; // Force the chatbot to open if embedded } // Removed css from here into the .css file - Refactored for Ver 1.7.3 // Initially hide the chatbot if (chatbot_chatgpt_start_status === 'closed') { chatGptChatBot.hide(); chatGptOpenButton.show(); } else { if (chatbot_chatgpt_display_style === 'floating') { if (chatbot_chatgpt_width_setting === 'Wide') { $('#chatbot-chatgpt').removeClass('chatbot-narrow chatbot-full').addClass('chatbot-wide'); } else { $('#chatbot-chatgpt').removeClass('chatbot-wide chatbot-full').addClass('chatbot-narrow'); } // Overrides for mobile devices - Ver 1.8.1 if (isMobile()) { // Initial update updateChatbotStyles(); // Listen for orientation changes window.addEventListener('orientationchange', updateChatbotStyles); // Listen for resize events window.addEventListener('resize', updateChatbotStyles); } chatGptChatBot.show(); chatGptOpenButton.hide(); } else { $('#chatbot-chatgpt').removeClass('chatbot-wide chatbot-narrow').addClass('chatbot-full'); } } chatbotContainer = $('
').addClass('chatbot-container'); // Changed this out for an image - Ver 1.8.6 // chatbotCollapseBtn = $('').addClass('chatbot-collapse-btn').addClass('dashicons dashicons-format-chat'); // Add a collapse button chatbotCollapseBtn = $('').addClass('chatbot-collapse-btn').append(chatbotcollapseicon); // Add a collapse button chatbotCollapsed = $('
').addClass('chatbot-collapsed'); // Add a collapsed chatbot icon dashicons-format-chat f125 // Avatar and Custom Message - Ver 1.5.0 selectedAvatar = encodeURIComponent(localStorage.getItem('chatbot_chatgpt_avatar_icon_setting')); if (isValidAvatarSetting(selectedAvatar)) { // Is valid avatar setting // DIAG - Diagnostics - Ver 1.8.1 // console.log('Chatbot: NOTICE: selectedAvatar: ' + selectedAvatar); } else { // Is not valid avatar setting // DIAG - Diagnostics - Ver 1.8.1 // console.error('Chatbot: ERROR: selectedAvatar: ' + selectedAvatar); selectedAvatar = 'icon-000.png'; } // Overrides for mobile devices - Ver 1.8.1 if (isMobile()) { // Set selectedAvatar to 'icon-000.png' for mobile devices, i.e., none selectedAvatar = 'icon-000.png'; } // Select the avatar based on the setting - Ver 1.5.0 if (selectedAvatar && selectedAvatar !== 'icon-000.png') { // FIXME - Add option for custom Avatar - Ver 1.8.6 let chatbot_chatgpt_custom_avatar_icon_setting = localStorage.getItem('chatbot_chatgpt_custom_avatar_icon_setting') || ''; if (chatbot_chatgpt_custom_avatar_icon_setting === '') { // Construct the path to the avatar avatarPath = plugins_url + '/assets/icons/' + selectedAvatar; } else { // Construct the path to the avatar avatarPath = chatbot_chatgpt_custom_avatar_icon_setting; // Use the custom URL } // IDEA - Add option to suppress avatar greeting in setting options page // IDEA - If blank greeting, don't show the bubble // IDEA - Add option to suppress avatar greeting if clicked on // Updated to address cross-site scripting - Ver 1.8.1 // If an avatar is selected, and it's not 'icon-000.png', use the avatar avatarImg = $('') .attr('id', 'chatbot_chatgpt_avatar_icon_setting') .attr('class', 'chatbot-avatar') .attr('src', avatarPath); // Get the stored greeting message. If it's not set, default to a custom value. avatarGreeting = localStorage.getItem('chatbot_chatgpt_avatar_greeting_setting') || 'Howdy!!! Great to see you today! How can I help you?'; // Create a bubble with the greeting message // Using .text() for safety, as it automatically escapes HTML bubble = $('
').text(avatarGreeting).addClass('chatbot-bubble'); // Append the avatar and the bubble to the button and apply the class for the avatar icon chatGptOpenButton.empty().append(avatarImg, bubble).addClass('avatar-icon'); } else { // If no avatar is selected or the selected avatar is 'icon-000.png', use the dashicon // Remove the avatar-icon class (if it was previously added) and add the dashicon class // chatGptOpenButton.empty().removeClass('avatar-icon').addClass('dashicons dashicons-format-chat dashicon'); // chatGptOpenButton.empty().removeClass('avatar-icon').addClass('dashicons chatbot-open-icon chatbotopenicon'); // Add an open button chatGptOpenButton.empty().removeClass('avatar-icon').addClass('chatbot-open-icon').append(chatbotopenicon); // Add an open button } // Append the collapse button and collapsed chatbot icon to the chatbot container $('#chatbot-chatgpt-header').append(chatbotCollapseBtn); chatbotContainer.append(chatbotCollapsed); // Add initial greeting to the chatbot conversation.append(chatbotContainer); function initializeChatbot() { isFirstTime = !localStorage.getItem('chatbot_chatgpt_opened') || false; // Remove any legacy conversations that might be store in local storage for increased privacy - Ver 1.4.2 localStorage.removeItem('chatbot_chatgpt_conversation'); // console.log('Chatbot: NOTICE: isFirstTime: ' + isFirstTime); if (isFirstTime) { // DIAG - Logging for Diagnostics // if (chatbotSettings.chatbot_chatgpt_diagnostics === 'On') { // console.log('Chatbot: NOTICE: initializeChatbot at isFirstTime'); // } initialGreeting = localStorage.getItem('chatbot_chatgpt_initial_greeting') || 'Hello! How can I help you today?'; // Don't append the greeting if it's already in the conversation if (conversation.text().includes(initialGreeting)) { return; } lastMessage = conversation.children().last().text(); // Don't append the subsequent greeting if it's already in the conversation - Ver 1.5.0 if (lastMessage === subsequentGreeting) { return; } appendMessage(initialGreeting, 'bot', 'initial-greeting'); localStorage.setItem('chatbot_chatgpt_opened', 'true'); // Save the conversation after the initial greeting is appended - Ver 1.2.0 sessionStorage.setItem('chatbot_chatgpt_conversation', conversation.html()); } else { // DIAG - Logging for Diagnostics - Ver 1.4.2 // if (chatbotSettings.chatbot_chatgpt_diagnostics === 'On') { // console.log('Chatbot: NOTICE: initializeChatbot at else'); // } initialGreeting = localStorage.getItem('chatbot_chatgpt_subsequent_greeting') || 'Hello again! How can I help you?'; // Don't append the greeting if it's already in the conversation if (conversation.text().includes(initialGreeting)) { return; } appendMessage(initialGreeting, 'bot', 'initial-greeting'); localStorage.setItem('chatbot_chatgpt_opened', 'true'); } return; } if (chatbot_chatgpt_display_style === 'floating') { // Add chatbot header, body, and other elements chatbotHeader = $('
').addClass('chatbot-header'); chatGptChatBot.append(chatbotHeader); // Add the chatbot button to the header $('#chatbot-chatgpt-header').append(chatbotCollapseBtn); chatbotHeader.append(chatbotCollapsed); // Attach the click event listeners for the collapse button and collapsed chatbot icon chatbotCollapseBtn.on('click', toggleChatbot); chatbotCollapsed.on('click', toggleChatbot); chatGptOpenButton.on('click', toggleChatbot); } else { // Embedded style - Do not add the collapse button and collapsed chatbot icon chatbotHeader = $('
'); } function appendMessage(message, sender, cssClass) { messageElement = $('
').addClass('chat-message'); // Convert HTML entities back to their original form let decodedMessage = $('